package com.gzrhhscd.controller;
import com.gzrhhscd.Pojo.Dept;
import com.gzrhhscd.Pojo.Result;
import com.gzrhhscd.anno.Log;
import com.gzrhhscd.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
//    private static Logger log= LoggerFactory.getLogger(DeptController.class);
//    @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @Autowired
    private DeptService deptService;
    @CrossOrigin(origins = "http://192.168.138.101")
    @GetMapping()
    public Result list(){
        log.info("查询全部部门数据。");
        List<Dept>deptList=deptService.list();
        return Result.success(deptList);
    }
    @Log
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) throws Exception {
        log.info("根据ID删除部门");
        deptService.delete(id);
        return Result.success();
    }
    @Log
    @PostMapping()
    public Result add(@RequestBody Dept dept){
        log.info("新增部门");
        deptService.add(dept);
        return Result.success();
    }
}
